<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('编辑日报')" />
	<th:block th:include ="include :: select2-css"/> 
    
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-hxDayReport-add">
			<input type="text" hidden="true" id="projectId" name="projectId" th:value="${hxDayReport.projectId}" required>
			<input type="text" hidden="true" id="hxDayReportId" name="id" th:value="${hxDayReport.id}" required>
 			<input type="text" hidden="true" id="workDate" name="workDate" th:value="${dateStr}" required>
 			<input type="text" hidden="true" id="workType" name="workType" th:value="${hxDayReport.workType}" >
 			<input type="text" hidden="true" id="workDescRes" name="workDescRes" th:value="${hxDayReport.workDesc}" required>		
		  <div class="form-group">	
				<label class="col-xs-2 control-label" id="xmnLable" style="display: none">所属项目：</label>
				<label class="col-xs-2 control-label" id="xmwLable"  style="display: none">项目外工作：</label>
                 <div class="col-xs-8">
					<input id="proname" name="proname" class="form-control" type="text" th:value="${hxDayReport.proname}" readonly="readonly">
				</div>
			</div>
			  <div class="form-group">
				  <label class="col-xs-2 control-label">工作时长：</label>
					<div class="col-sm-8">
						<input id="workTime" name="workTime" class="form-control zhsCount" type="text" th:value="${hxDayReport.workTime}" required><font color="red">[工时统计最小单位0.5]</font>
					</div>
			  </div>
			
					
			<div class="form-group">	
				<label class="col-xs-2 control-label">工作内容：</label>
				<div class="col-sm-8">
					<textarea  class="form-control" rows="12" cols="" id="workDesc" name="workDesc" required></textarea>
				</div>
			</div>
			<div class="form-group" hidden="true">	
				<label class="col-sm-3 control-label">日报所属用户ID：</label>
				<div class="col-sm-8">
					<input id="userId" name="userId" class="form-control" type="text">
				</div>
			</div>
		</form>
		<button style="background-color: orange;font-size: 12px; width: 56px;height: 32px" onclick="delOne()" >删除</button>
	</div>
    <div th:include="include::footer"></div>
       <th:block th:include ="include :: select2-js"/>
    <script type="text/javascript">
	
    $(function(){
    	
    	var workType = $("#workType").val();
    	if(workType == "1"){
    		$("#xmnLable").show();
    	}
    	if(workType == "2"){
    		$("#xmwLable").show();
    	}
    	
    	//1. 回显 工作内容
    	workDescRes = $("#workDescRes").val();
    	var workDescArr = workDescRes.split("@@");
    	var showContentStr ="";
    	for(var i=0;i<workDescArr.length;i++){
    		showContentStr += workDescArr[i]+'\n';
    	}
    	showContentStr = showContentStr.substring(0,showContentStr.length-2);
    	$("#workDesc").val(showContentStr);
    	
    	//$(".layui-layer-btn layui-layer-btn-").html('<a class="layui-layer-btn0">确定</a>');
    	
/*     	
	    $('#projectSelect').select2({
            placeholder:"请选择岗位",
            allowClear: true
        });
	    
	    $('#projectSelect').on('select2:select', function (e) {
	    	  var projectId = e.params.data.id;
	    	  var projectType = $("#projectSelect").find("option:selected").attr("projecttype"); //获取自定义属性 项目类型projecttype
	    	  $('#projectId').val(projectId);
	    	  $('#projectType').val(projectType);
	    }); */
    });	
    var prefix = ctx + "system/hxDayReport"
		$("#form-hxDayReport-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
    function delOne(){
    	$.modal.confirm("确认要删除这条工作吗?", function() {
    		var hxDayReportId  = $("#hxDayReportId").val();
            $.ajax({
                type: "post",
                url: prefix + "/remove",
                data: {
                    "ids": hxDayReportId,
                },
                //async: false,
                success: function (data) {
                	 $.modal.close();
                	 parent.location.reload();
                }
            });
		});
    	
    }
		function submitHandler() {
/* 			  var projectId = $('#projectId').val();
			  if(projectId =='' || projectId ==null){
				  $.modal.alertWarning("请选择项目!");
				  $('#workDesc').val('');
			  } */
			
			var formattDesc = '';
			var workDesc = $('#workDesc').val();
		    var workDescArr = workDesc.split('\n');
		    for(var i=0;i<workDescArr.length;i++){
		    	if(workDescArr[i] !='' && workDescArr[i] != null){
		    		formattDesc += workDescArr[i]+'@@';
			    }
		    }
		    $('#workDesc').val(formattDesc); //工作描述追加 @@ 字符，方便日历格子中分条显示
		    
	        if(!$.validate.form()){
	        	 $('#workDesc').val('');
	        }
		    if ($.validate.form()) {
	            $.operate.save(prefix + "/editOneSave", $('#form-hxDayReport-add').serialize());
	        }
	    }
/* 		function selectProject(){
			$.modal.open("选择项目", ctx + "system/hxProject/chooseProject");
		} */
	</script>
</body>
</html>
